﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using vukhoas.src.POJO;
using vukhoas.src;
using System.Data.SqlClient;
using System.IO;

namespace vukhoas
{
    public partial class AppleProduct : System.Web.UI.Page
    {
        protected List<Product> lstProduct;
        protected void Page_Load(object sender, EventArgs e)
        {
            lstProduct = getLstProduct();
        }        
        private List<Product> getLstProduct()
        {
            List<Product> lst = new List<Product>();   
            SqlConnection conn = MyConnect.getConnection();
            conn.Open();
            try
            {                             
                String sql = "SELECT * FROM product";
                SqlCommand cmd = new SqlCommand(sql,conn);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    Product pro = new Product();
                    pro.Id = dr.GetInt32(0);
                    pro.Name = dr.GetString(1);
                    pro.Price = dr.GetString(2);
                    pro.ManufactureID = dr.GetString(3);
                    pro.CategoryID = dr.GetString(4);
                    pro.Detail = dr.GetString(5);
                    pro.Introduce = dr.GetString(6);
                    pro.Information = dr.GetString(7);
                    pro.Image = dr.GetString(8);
                    pro.CreatedDate = dr.GetDateTime(9);
                    lst.Add(pro);
                } 
            }
            catch (Exception ex)
            {
                Response.Write("Error: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return lst ;
        }        
    }
}
